package com.demo2do.fms.admin.entity.query;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;


/**
 * 查询装卸地代码所用条件
 * 
 * @author Chang Liu
 *
 */

public class WarehouseQuery implements QueryBuilder {
	
    /**仓库代码*/
	private String code;
	
	/**仓库名称*/
	private String name;
	
	/**仓库所在装卸地*/
	private String loadPlaceName;
	
	private QueryOrder order;
	    
	private QueryFilter filter;

	/**
	 * 
	 */
	public WarehouseQuery(){
		order = new QueryOrder();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
    public QueryFilter getPreparedFilter(boolean refresh) {
		
		if(filter == null || refresh) {

			filter = new QueryFilter().addLike("code", code)
					                  .addLike("name", name)
			                          .addLike("loadPlaceName", loadPlaceName);
        }
		 return filter;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		String sentence = "FROM Warehouse WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		return sentence;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/**
	 * 
	 * @return
	 */
	public QueryFilter getFilter(){
		return getPreparedFilter(false);
	}

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the loadPlaceName
     */
    public String getLoadPlaceName() {
        return loadPlaceName;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param loadPlaceName the loadPlaceName to set
     */
    public void setLoadPlaceName(String loadPlaceName) {
        this.loadPlaceName = loadPlaceName;
    }

}
